package com.gu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gu.VO.ServerResponse;
import com.gu.dao.NoticeDAO;
import com.gu.entity.NoticeDO;
import com.gu.service.NoticeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName: apartment-management-center
 * @Package: com.gu.service.impl
 * @ClassName: NoticeServiceImpl
 * @Author: gusongliao
 * @Description: 公告业务层
 * @createDate 2021/03/18 19:38
 */

@Service
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    private NoticeDAO noticeDAO;

    @Override
    public PageInfo getNoticeBySearchParam(Integer pageNum, Integer pageSize,String searchParam, String searchDate) {
        PageHelper.startPage(pageNum,pageSize);
        List<NoticeDO> noticeDOList = noticeDAO.getNoticeBySearchParam(searchParam, searchDate);
        PageInfo pageInfo = PageInfo.of(noticeDOList);
        return pageInfo;
    }

    @Override
    public ServerResponse insertNotice(NoticeDO noticeDO) {
        int result = noticeDAO.insert(noticeDO);
        if (result == 1){
            return ServerResponse.SUCCESS;
        }
        return ServerResponse.error(7,"新增公告失败");
    }

    @Override
    public NoticeDO getById(Integer id) {
        return noticeDAO.getById(id);
    }

    @Override
    public ServerResponse deleteByIds(Integer[] ids) {
        Integer result = noticeDAO.deleteByIds(ids);
        if (result == ids.length){
            return ServerResponse.SUCCESS;
        }
        return ServerResponse.error(14,"删除公告失败");
    }

}
